home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format 117
/
af117a.adf
/
archives
/
af117a1.lzx
/
Fiasco_2.2
/
Databases
/
Mailing List Archive
/
importmails.frx
< prev
next >
Wrap
Text File
|
1983-01-16
|
9KB
|
370 lines
/* importmails.frx
* Copyright © 1998 Nils Bandener
* $VER: importmails_frx 8.5 (31.7.98)
*/
/* Please specify here a name for the ARexx script:
*/
scriptname = "Import Mails"
Options Results
Parse Arg filename
/*
* If not called from Fiasco, try to address the active
* Fiasco project
*/
if ~abbrev(address(), "FIASCO.") then
do
/* Get list of all available ports */
ports = show("Ports")
/* Search for a port of Fiasco */
do i = 1 to words(ports)
if abbrev(word(ports, i), "FIASCO.") then
do
/* A port of Fiasco has been found.
* Now query Fiasco to return the port
* name of the active database.
*/
Address Value word(ports, i)
GetAttr Project Name Active ARexx
Address Value Result
break
end
end
end
fiasco_port = address()
Signal on Syntax
Signal on Halt
Signal on Break_C
Signal on Failure
LockGUI
if filename = "" then
do
RequestFile 'NoIcons var filename'
end
if filename ~= "" then
do
if open(f, filename, "r") then
do
header = 1
body = ""
/*
* Insert record at the end of the database
*/
CountRecords 'var insertrec'
AddRecord 'Inactive Record ' || insertrec || ' Var recnum'
do while ~eof(f)
ln = readln(f)
if header then
do
/* Parsing of RFC messages
*/
if upper(left(ln, 5)) = "FROM:" then
do
val = strip(substr(ln, 7), 'B', '"')
SetField 'From Record ' || recnum || ' "' || val || '"'
end
else if upper(left(ln, 11)) = "MESSAGE-ID:" then
do
val = substr(ln, 13)
val = strip(val, "L", "<")
val = strip(val, "T", ">")
SetField 'MessageID Record ' || recnum || ' "' || val || '"'
end
else if upper(left(ln, 8)) = "SUBJECT:" then
do
val = substr(ln, 10)
SetField 'Subject Record ' || recnum || ' "' || val || '"'
end
else if upper(left(ln, 5)) = "DATE:" then
do
val = substr(ln, 7)
spos = pos(",", val)
if spos ~= 0 then
do
val = substr(val, spos + 2)
end
dateday = word(val, 1)
datemonthstr = word(val, 2)
dateyear = word(val, 3)
if datemonthstr = "Jan" then
datemonth = 1
else if datemonthstr = "Feb" then
datemonth = 2
else if datemonthstr = "Mar" then
datemonth = 3
else if datemonthstr = "Apr" then
datemonth = 4
else if datemonthstr = "May" then
datemonth = 5
else if datemonthstr = "Jun" then
datemonth = 6
else if datemonthstr = "Jul" then
datemonth = 7
else if datemonthstr = "Aug" then
datemonth = 8
else if datemonthstr = "Sep" then
datemonth = 9
else if datemonthstr = "Oct" then
datemonth = 10
else if datemonthstr = "Nov" then
datemonth = 11
else if datemonthstr = "Dec" then
datemonth = 12
dateval = dateday || "." || datemonth || "." || dateyear
timeval = word(val, 4)
SetField 'Date Record ' || recnum || ' "' || dateval || '"'
SetField 'Time Record ' || recnum || ' "' || timeval || '"'
end
else if upper(left(ln, 12)) = "IN-REPLY-TO:" then
do
val = substr(ln, 14)
val = strip(val, "L", "<")
val = strip(val, "T", ">")
SetField 'Reference Record ' || recnum || ' "' || val || '"'
end
else if upper(left(ln, 11)) = "REFERENCES:" then
do
val = substr(ln, 13)
val = strip(val, "L", "<")
val = strip(val, "T", ">")
SetField 'Reference Record ' || recnum || ' "' || val || '"'
end
/* Parsing of ZCONNECT messages
*/
else if left(ln, 4) = "ABS:" then
do
val = substr(ln, 5)
SetField 'From Record ' || recnum || ' "' || val || '"'
end
else if left(ln, 4) = "MID:" then
do
val = substr(ln, 5)
SetField 'MessageID Record ' || recnum || ' "' || val || '"'
end
else if left(ln, 4) = "BET:" then
do
val = substr(ln, 5)
SetField 'Subject Record ' || recnum || ' "' || val || '"'
end
else if left(ln, 4) = "EDA:" then
do
val = substr(ln, 5)
dateval = substr(val, 7, 2) || "." || substr(val, 5, 2) || "." || substr(val, 1, 4)
timeval = substr(val, 9, 2) || ":" || substr(val, 11, 2) || ":" || substr(val, 13, 2)
SetField 'Date Record ' || recnum || ' "' || dateval || '"'
SetField 'Time Record ' || recnum || ' "' || timeval || '"'
end
else if left(ln, 4) = "BEZ:" then
do
val = substr(ln, 5)
SetField 'Reference Record ' || recnum || ' "' || val || '"'
end
else if length(ln) = 0 then
do
header = 0
end
end
else
do
/*
* Escape *, " and newlines
*/
p = 1
do forever
p = pos('*', ln, p)
if p ~= 0 then do
ln = substr(ln, 1, p - 1) || '**' || substr(ln, p + 1)
p = p + 2
end
else break
end
p = 1
do forever
p = pos('"', ln, p)
if p ~= 0 then do
ln = substr(ln, 1, p - 1) || '*"' || substr(ln, p + 1)
p = p + 2
end
else break
end
body = body || ln || "*n"
end
end
SetField 'MailBody Record ' || recnum || ' "' || body || '"'
GetField 'From Record ' || recnum || ' var from'
realname = from
email = from
openbracket = pos("(", from)
if openbracket ~= 0 then
do
closebracket = pos(")", from, openbracket)
if closebracket ~= 0 then
do
realname = substr(from, openbracket + 1, closebracket - openbracket - 1)
email = trim(substr(from, 1, openbracket - 1))
end
end
else
do
openbracket = pos("<", from)
if openbracket ~= 0 then
do
closebracket = pos(">", from, openbracket)
realname = substr(from, 1, openbracket - 1)
email = substr(from, openbracket + 1, closebracket - openbracket - 1)
end
end
SetField 'RealName Record ' || recnum || ' "' || realname || '"'
SetField 'EMail Record ' || recnum || ' "' || email || '"'
call close(f)
end
else
do
RequestChoice '"Could not open file" "Cancel"'
end
end
bail_out:
Address Value fiasco_port
UnlockGUI
ResetStatus
exit
syntax:
failure:
if show("Ports", fiasco_port) then
do
Address Value fiasco_port
RequestChoice '"Error ' || rc || ' in line ' || sigl || ':*n' || errortext(rc) || '" "Cancel" Title "' || scriptname || '"'
end
else
do
say "Error" rc "in line" sigl ":" errortext(rc)
say "Enter to continue"
pull dummy
end
call bail_out
halt:
break_c:
if show("Ports", fiasco_port) then
do
Address Value fiasco_port
RequestChoice '"Script Abort Requested" "Abort Script" Title "' || scriptname || '"'
end
else
do
say "*** Break"
say "Enter to continue"
pull dummy
end
call bail_out